package com.glacier.cloud.ad.config;

import com.glacier.cloud.ad.consts.Constant;
import com.glacier.cloud.ad.consumer.Demo2Consumer;
import com.glacier.cloud.ad.consumer.Demo3Consumer;
import com.glacier.cloud.ad.consumer.OrderCreateEventConsumer;
import com.glacier.cloud.ad.entity.dto.event.OrderCreateEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.function.Consumer;
import java.util.function.Function;

/**
 * date 2024-01-24 22:05
 *
 * @author glacier
 * @version 1.0
 */
@Slf4j
@Configuration
public class ConsumerConfig {
    /**
     * demo1 消费者
     * 注意bean名称 demo 要与配置文件中的spring.cloud.stream.bindings.demo-in-0 保持一致
     * 其中 -in-0 是固定写法，in 标识消费者类型，0是消费者索引
     *
     * @return
     */
    @Bean
    public Consumer<OrderCreateEvent> demo1() {
        return new OrderCreateEventConsumer();
    }

    /**
     * demo2 消费者
     *
     * @return
     */
    @Bean(Constant.DEMO2)
    public Consumer<String> consumer2() {
        return new Demo2Consumer();
    }

    /**
     * demo3 消费者
     *
     * @return
     */
    @Bean(Constant.DEMO3)
    public Consumer<String> consumer3() {
        return new Demo3Consumer();
    }

    /**
     * demo4 消费者
     *
     * @return
     */
    @Bean
    public Consumer<String> demo4() {
        return (str) -> {
            log.info("demo4 接收消息： {}", str);
        };
    }

    /**
     * demo5 消费者
     *
     * @return
     */
    @Bean
    public Consumer<String> demo5() {
        return (str) -> {
            log.info("demo5 接收消息： {}", str);
        };
    }

    @Bean
    public Function<String, String> toUpperCase() {
        return String::toUpperCase;
    }
}
